<?php

namespace App\Http\Controllers;

use App\Library\Lock;
use App\Library\Requests\Base\IdRequest;
use App\Library\Requests\Kefu\KefuChangeStatusRequest;
use App\Library\Requests\Kefu\KefuPageRequest;
use App\Library\Requests\Kefu\KefuTurnRequest;
use App\Library\Service\KefuService;
use Illuminate\Http\JsonResponse;

class KefuController extends BaseController
{
    /**
     * @param KefuService $service
     */
    public function __construct(KefuService $service)
    {
        $this->service = $service;
    }

    /**
     * status
     * @return JsonResponse
     */
    public function status(): JsonResponse
    {
        return $this->service->status();
    }

    /**
     * paging
     * @param KefuPageRequest $request
     * @return JsonResponse
     */
    public function paging(KefuPageRequest $request): JsonResponse
    {
        return $this->service->paging($request);
    }

    /**
     * changeStatus
     * @param KefuChangeStatusRequest $request
     * @return JsonResponse
     */
    public function changeStatus(KefuChangeStatusRequest $request): JsonResponse
    {
        return $this->service->changeStatus($request);
    }

    /**
     * turn
     * @param KefuTurnRequest $request
     * @return JsonResponse
     */
    public function turn(KefuTurnRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__, function () use ($request) {
            return $this->service->turn($request);
        });
    }

    /**
     * end
     * @param IdRequest $request
     * @return JsonResponse
     */
    public function end(IdRequest $request): JsonResponse
    {
        return $this->service->end($request);
    }

    /**
     * consultList
     * @return JsonResponse
     */
    public function consultList(): JsonResponse
    {
        return $this->service->consultList();
    }
}
